--构造一个触发器trg_AuditLog，在向Employees表中插入一条数据的时候，触发插入相关的数据到AuditLog中。

-- 职员表
--后台会往Employees插入一条数据:
--INSERT INTO Employees (NAME,AGE,ADDRESS,SALARY)VALUES ('Paul', 32, 'California', 20000.00 );
--然后从AuditLog里面使用查询语句:
--select * from AuditLog;
use Aaa
GO
CREATE TABLE Employees
(
   Id INT PRIMARY KEY NOT NULL identity,
   Name nvarchar(80) NOT NULL,
   Age INT NOT NULL,
   Address NVARCHAR(50),
   SALARY decimal(18,2)
);
-- 审计日志表

CREATE TABLE AuditLog
(
   Id int primary key not null identity,
   NAME TEXT NOT NULL,
   Salary decimal(18,2)
);

INSERT INTO Employees (NAME,AGE,ADDRESS,SALARY)VALUES ('Paul', 32, 'California', 20000.00 )
go
alter trigger trg_AuditLog
on Employees
instead of  insert
as
begin
	select * from deleted
	select * from inserted
	insert into AuditLog(NAME,Salary) values ((select Name from inserted),(select Salary from inserted))
	end
	go
	select * from AuditLog